<?php 
	header("content-type:text/html;charset=utf-8");
	include('connect.php');
	$d = (new Datetime)->format('Y-m-d H:i:s');
	$sql1 = "select * from totalinfo order by time desc limit 1 ";
	$sql2 = "select * from northinfo order by time desc limit 1 ";
	$sql3 = "select * from southinfo order by time desc limit 1 ";
	$sql4 = "select * from areainfo where area = 'south'";
	$sql5 = "select * from areainfo where area = 'north'";
	$row1 =mysqli_fetch_assoc($db->query($sql1));
	$row2 =mysqli_fetch_assoc($db->query($sql2));
	$row3 =mysqli_fetch_assoc($db->query($sql3));
	$row4 =mysqli_fetch_assoc($db->query($sql4));
	$row5 =mysqli_fetch_assoc($db->query($sql5));
	function valueColor($value){
		if($value <= 60){
			$valueColor = "#31fa00";
		}elseif($value <= 80){
			$valueColor = "yellow";
		}elseif($value <= 100){
			$valueColor = "orange";
		}else{
			$valueColor = "#fc3c3c";
		}	
		return $valueColor;
	}
	
	$totalNum = $row2['nowValue']+$row3['nowValue'];
	$totalLoadFactorNum = round(($totalNum*100/$row1['maxValue']),1);
	// 	if($totalNum==0){
	// 		$totalState = "关闭";
	// 	}elseif($totalLoadFactorNum <= 60){
	// 		$totalState = "正常";
	// 	}elseif($totalLoadFactorNum <= 80){
	// 		$totalState = "拥挤";
	// 	}elseif($totalLoadFactorNum < 100){
	// 		$totalState = "饱和";
	// 	}elseif($totalLoadFactorNum >= 100){
	// 		$totalState = "超载";	
	// 	}
	// if ($row1['nowState']=="疏散中"){
	// 	$totalState="疏散中";
	// 	$emcplace = $row1['emcplace'];
	// 	$emcName = $row1['emcName'];
	// 	$sqlWriteTotalNum = "update totalinfo set time = '{$d}', nowValue = {$totalNum}, nowState = '{$totalState}', `maxValue` = 12000, emcplace = '{$emcplace}' ,emcName = '{$emcName}'";
	// }else{
	// 	$sqlWriteTotalNum = "update totalinfo set time = '{$d}', nowValue = {$totalNum}, nowState = '{$totalState}', `maxValue` = 12000";
	// }
	// echo $row1['nowState'],",",$totalState;
	// echo $sqlWriteTotalNum;
	// $db->query($sqlWriteTotalNum);//返回总人数给数据库	
	$northNum = (int)($row2['nowValue']*100/$row5['maxValue']);
	$southNum = (int)($row3['nowValue']*100/$row4['maxValue']);
	// echo $northNum,",",$southNum;
	$northColor = valueColor($northNum);
	$southColor = valueColor($southNum);
	if($row2['lastValue'] < $row2['nowValue']){
		$northChange = "↑";
	}else if($row2['lastValue'] > $row2['nowValue']){
		$northChange = "↓";
	}else{
		$northChange = "-";
	}
	if($row3['lastValue'] < $row3['nowValue']){
		$southChange = "↑";
	}else if($row3['lastValue'] > $row3['nowValue']){
		$southChange = "↓";
	}else{
		$southChange = "-";
	}
	$row1 =mysqli_fetch_assoc($db->query($sql1));
	
	// echo $totalLoadFactorNum;
	$totalColor = valueColor($totalLoadFactorNum);
	echo 
		"<div id='mainAreaStatusBarTotal'>总人数：<div id='mainAreaStatusBarTotalNum' style='color:$totalColor;'>".$row1['nowValue']."</div></div>";
		// 
	echo 
		"<div id='mainAreaStatusBarTotalLoadFactor'>总负载率：<div id='mainAreaStatusBarTotalLoadFactorNum' style='color:$totalColor;'>".$totalLoadFactorNum."%</div></div>";
			// 
	echo
		"<div id='mainAreaStatusBarAreaNorth'>北区人数：<div id='mainAreaStatusBarAreaNorthNum' style='color:$northColor;'>".$row2['nowValue']." $northChange</div></div>";
			// 
	echo
		"<div id='mainAreaStatusBarAreaNorth'>南区人数：<div id='mainAreaStatusBarAreaNorthNum' style='color:$southColor;'>".$row3['nowValue']." $southChange</div></div>";
			// 
	echo 
		"<div id='mainAreaStatusBarTotal'>总体状态：<div id='mainAreaStatusBarTotalNum' style='color:$totalColor;'>".$row1['nowState']."</div></div>";
			// 
	echo 
		"<div id='mainAreaStatusBarFlushTime'>更新时间：".$row1['time']."</div>"
 ?>